package cn.yunhe.controller;

import cn.yunhe.model.House;
import cn.yunhe.service.HouseBiz;
import cn.yunhe.util.BaseActionUtil;

import java.util.List;

public class HouseAction extends BaseActionUtil {
    private HouseBiz houseBiz;

    public String searchHouse(){
        List<House>houseList=houseBiz.searchHouse("from House ");
        list(houseList);
        getRequest().setAttribute("houseList",houseList);
        return SUCCESS;
    }

    public HouseBiz getHouseBiz() {
        return houseBiz;
    }

    public void setHouseBiz(HouseBiz houseBiz) {
        this.houseBiz = houseBiz;
    }


    public void list(List<House> houseList){
        for (House house:houseList){
            singleHouse(house);
        }
    }

    public void singleHouse(House house){
        System.out.print(house.getHid()+"\t");
        System.out.print(house.getHtitle()+"\t");
        System.out.print(house.getHprice()+"\t");
        System.out.print(house.getHfloorage()+"\t");
        System.out.print(house.getHpubdate()+"\t");
        System.out.print(house.getHcontact()+"\t");
        System.out.print(house.getHdesc()+"\t");
        System.out.print(house.getHflag()+"\t");
        if (house.getMember().getMname()!=null)
            System.out.print(house.getMember().getMname()+house.getMember().getMid()+"\t");
        if (house.getType().getTname()!=null)
            System.out.print(house.getType().getTname()+house.getType().getTid()+"\t");
        if (house.getStreet().getSname()!=null)
            System.out.print(house.getStreet().getSname()+house.getStreet().getSid()+"\t");
        if (house.getStreet().getDistrict().getDname()!=null)
            System.out.print(house.getStreet().getDistrict().getDname()+house.getStreet().getDistrict().getDid()+"\t");
        System.out.println();
    }


}
